package com.info.zhiduoduo.weixin.controller;

import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseAuthInfo;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.entity.maker.Maker;
import com.info.zhiduoduo.repository.entity.maker.MakerAccount;
import com.info.zhiduoduo.repository.entity.maker.MakerRescissionApply;
import com.info.zhiduoduo.weixin.formbean.crowdsource.UpdateEmergencyContactFormBean;
import com.info.zhiduoduo.weixin.formbean.maker.*;
import com.info.zhiduoduo.weixin.formbean.project.ProjectIdFormBean;
import com.info.zhiduoduo.weixin.formbean.system.RegFormBean;
import com.info.zhiduoduo.weixin.service.MakerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

@Api(tags = "创客接口")
@RestController
@RequestMapping("/user")
public class MakerController extends CommonController {

	@Autowired
	MakerService makerService;

	/**
	 注册(绑定手机号)
	 */
	@GetMapping("/v1/test")
	@ResponseBody
	public SmartResult test() {
		int a = 1/0;
		return null;
	}

	/**
	 注册(绑定手机号)
	 */
	@PostMapping("/v1/regUser")
	public SmartResult regUser(@RequestBody BaseSimpleFormBean<RegFormBean> baseSimpleFormBean) {

		return makerService.regUser(baseSimpleFormBean);
	}

	/**
	 获取创客工作室信息
	 */
	@PostMapping("/v1/getUserInfo")
	public SmartResult getUserInfo(@RequestBody BaseAuthInfo baseAuthInfo) {
		return makerService.getUserInfo(baseAuthInfo);
	}

	/**
	 更新创客工作室的经营范围
	 */
	@PostMapping("/v1/bizScope")
	public SmartResult updateBizScope(@RequestBody BaseSimpleFormBean<BizScopeFormBean> baseSimpleFormBean) {
		return makerService.updateBizScope(baseSimpleFormBean);
	}

	/**
	 更新创客工作室信息
	 */
	@PostMapping("/v1/updateUserInfo")
	public SmartResult updateUserInfo(@RequestBody BaseSimpleFormBean<UpdateMakerInfoFormBean> baseSimpleFormBean) {
		return makerService.updateUserInfo(baseSimpleFormBean);
	}

	/**
	 实名认证
	 */
	@ZddLog(name = "微信实名认证")
	@PostMapping("/v1/realNameAuth")
	public SmartResult realName(@RequestBody BaseSimpleFormBean<RealNameAuthFormBean> baseSimpleFormBean) {
		return makerService.realNameAuth(baseSimpleFormBean);
	}

	@ZddLog(type = ZddLogType.UPDATE,name = "更新创客实名信息",entities = @LogEntity(entity = Maker.class,parameters =
	@LogParameter(fields = "userid",parameters = "formBean.userid")))
	@ApiModelProperty("更新创客实名信息")
	@PostMapping("/v1/updateRealNameInfo")
	public SmartResult updateRealNameInfo(@RequestBody BaseSimpleFormBean<RealNameAuthFormBean> formBean) {
		return makerService.updateRealNameInfo(formBean);
	}

	/**
	 设置支付密码
	 */
	@PostMapping("/v1/setPayPwd")
	public SmartResult updatePayPwd(@RequestBody BaseSimpleFormBean<PayPwdFormBean> baseSimpleFormBean) {
		return makerService.updatePayPwd(baseSimpleFormBean);
	}

	/**
	 校验支付密码
	 */
	@PostMapping("/v1/checkPayPwd")
	public SmartResult checkPayPwd(@RequestBody BaseSimpleFormBean<PayPwdFormBean> baseSimpleFormBean) {
		return makerService.getPayPwdForCheck(baseSimpleFormBean);
	}

	/**
	 忘记支付密码
	 */
	@PostMapping("/v1/forgetPayPwd")
	public SmartResult forgetPayPwd(@RequestBody BaseSimpleFormBean<ForgetPayPwdFormBean> baseSimpleFormBean) {
		return makerService.updatePayPwdForForget(baseSimpleFormBean);
	}

	/**
	 银行卡验证
	 */
	@ZddLog(type = ZddLogType.UPDATE,name = "银行卡验证")
	@PostMapping("/v1/bankcardAuth")
	public SmartResult bankcardAuth(@RequestBody BaseSimpleFormBean<BankcardAuthFormBean> formBean) {
		return makerService.bankcardAuth(formBean);
	}

	/**
	 获取有效的银行卡
	 */
	@PostMapping("/v1/validBankecard")
	public SmartResult getBankcardList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getValidBankcard(formBean);
	}

	/**
	 获取所有的标签
	 */
	@PostMapping("/v1/allTag")
	public SmartResult getAllTag(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getAllTag(formBean);
	}

	/**
	 用户添加标签
	 */
	@ZddLog(name = "用户添加标签")
	@PostMapping("/v1/addTag")
	public SmartResult addTag(@RequestBody BaseSimpleFormBean<String> formBean) {
		return makerService.addTag(formBean);
	}

	@PostMapping("/getDefaultTagList")
	public SmartResult getDefaultTagList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getDefaultTagList(formBean);
	}

	/**
	 获取所有工作室领域分类
	 */
	@PostMapping("/v1/allField")
	public SmartResult getAllField(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getAllField(formBean);
	}

	/**
	 创客添加案例
	 */
	@ZddLog(name = "创客添加案例")
	@PostMapping("/v1/addEditCase")
	public SmartResult addEditCase(@RequestBody BaseSimpleFormBean<AddCaseFormBean> formBean) {
		return makerService.addEditCase(formBean);
	}

	/**
	 获取案例列表
	 */
	@PostMapping("/v1/caseList")
	public SmartResult getCaseList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getCaseList(formBean);
	}

	/**
	 删除案例
	 */
	@PostMapping("/v1/delCase")
	public SmartResult delCase(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return makerService.delCase(formBean);
	}

	/**
	 * 通过openid 获取用户信息
	 */
	@PostMapping("/getUserByOpenid")
	public SmartResult getUser(@RequestBody BaseSimpleFormBean<String> formBean) {
		return makerService.getUserByOpenid(formBean);
	}

	/**
	 * 绑定后台创建的创客
	 */
	@ZddLog(name = "绑定后台创建的创客")
	@PostMapping("/bindUser")
	public SmartResult bindUser(@RequestBody BaseSimpleFormBean<BindMakerFormBean> formBean) {
		return makerService.bindUser(formBean);
	}

	@PostMapping("/v1/accountStatistics")
	public SmartResult getUserAccountStatistics(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getUserAccountStatistics(formBean);
	}

	/**
	 * 用户统一平台协议
	 */
	@PostMapping("/v1/agreeProtocol")
	public SmartResult agreeProtocol(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.agreeProtocol(formBean);
	}

	@ApiOperation("完税记录")
	@PostMapping("/v1/finishTaxList")
	public SmartResult getFinishTaxList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getFinishTaxList(formBean);
	}

	@ApiOperation("年检记录")
	@PostMapping("/v1/annualCheckList")
	public SmartResult getAnnualCheckList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getAnnualCheckList(formBean);
	}

	@ApiOperation("年度汇算清缴记录")
	@PostMapping("/v1/finalSettlementList")
	public SmartResult getFinalSettlementList(@RequestBody BaseSimpleFormBean formBean) {
		return makerService.getFinalSettlementList(formBean);
	}

	@ApiOperation("编辑邮箱")
	@PostMapping("/editEmail")
	public SmartResult editEmail(@Valid @RequestBody BaseSimpleFormBean<EmailFormBean> formBean) {
		return makerService.editMail(formBean);
	}

//	@ApiOperation("将项目合同发到邮箱")
//	@PostMapping("/sendContractEmail")
//	public SmartResult sendContractEmail(@Valid @RequestBody BaseSimpleFormBean<ProjectIdFormBean> formBean) {
//		return makerService.sendContractEmail(formBean);
//	}

	@ApiOperation("将项目合同发到邮箱(PDF文件)")
	@PostMapping("/sendPdfContractEmail")
	public SmartResult sendPdfContractEmail(@Valid @RequestBody BaseSimpleFormBean<ProjectIdFormBean> formBean) {
		return makerService.sendPdfContractEmail(formBean);
	}

	@ZddLog(name = "申请解约")
	@ApiOperation("申请解约")
	@PostMapping("/applyRescission")
	public SmartResult applyRescission(@RequestBody BaseSimpleFormBean<ApplyRescissionFormBean> formBean) {
		return makerService.applyRescission(formBean);
	}

	@ApiOperation("CEO处理提交注销申请")
	@PostMapping("/processRescissionApply")
	public SmartResult processRescissionApply(@RequestBody BaseSimpleFormBean<ProcessRescissionApplyFormBean> formBean) {
		return makerService.processRescissionApply(formBean);
	}

	@ApiOperation("返回接口凭证")
	@PostMapping("/getCancelVoucher")
	public SmartResult getCancelVoucher(@RequestBody BaseSimpleFormBean<MakerCancelVoucher> formBean){
    return  makerService.getCancelVoucher(formBean);
	}

	@ZddLog(name = "上传工商认证图片")
	@ApiOperation("上传工商认证图片")
	@PostMapping("/saveBusinessAuthenticationImg")
	public SmartResult saveBusinessAuthenticationImg(@Valid @RequestBody BaseSimpleFormBean<BusinessAuthenticationFormBean> formBean) {
		return makerService.saveBusinessAuthenticationImg(formBean);
	}

	@ApiOperation("共青城注册工商户")
	@PostMapping("/registeredBusiness")
	public SmartResult registeredBusiness(@RequestBody BaseSimpleFormBean<RegisteredBusinessFormBean> formBean){
		return makerService.registeredBusiness(formBean);
	}

	@ApiOperation("保存创客录制的视频和电子签名")
	@PostMapping("/saveMakerVideoAndSignature")
	public SmartResult saveMakerVideoAndSignature(@RequestBody BaseSimpleFormBean<SaveVideoAndSignatureFormBean> formBean) {
		return makerService.saveMakerVideoAndSignature(formBean);
	}

	@ApiOperation("修改紧急联系人姓名及电话")
	@PostMapping("/updateEmergencyContact")
	public SmartResult updateEmergencyContact(@RequestBody BaseSimpleFormBean<UpdateEmergencyContactFormBean> formBean) {
		return makerService.updateEmergencyContact(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE,name = "更新电子签名",entities = @LogEntity(entity = MakerAccount.class,parameters =
	@LogParameter(fields = "userid",parameters = "formBean.userid")))
	@ApiOperation("更新电子签名")
	@PostMapping("/updateElectronicSignature")
	public SmartResult updateElectronicSignature(@RequestBody BaseSimpleFormBean<String> formBean) {
		return makerService.updateElectronicSignature(formBean);
	}

	@ZddLog(name = "增加上传委托定税的视频")
	@ApiOperation(value = "增加上传委托定税的视频", notes = "reqdata为视频文件保存路径，通过/common/uploadFile接口上传视频，获取保存路径")
	@PostMapping("/saveEntrustTaxVideo")
	public SmartResult saveEntrustTaxVideo(@RequestBody BaseSimpleFormBean<String> formBean) {
		return makerService.saveEntrustTaxVideo(formBean);
	}

	@ApiOperation(value = "发送微信通知，创客加急开税户")
	@PostMapping("/manualSendNotify")
	public SmartResult manualSendNotify(@RequestBody BaseSimpleFormBean<ManualSendNotifyFormBean> formBean) {
		return makerService.manualSendNotify(formBean.getReqdata());
	}

}
